#include <accent/algorithms/filter.hpp>
#include "test_base.hpp"

template <typename Container>
auto filterc(Container& c) -> decltype(filter(all(c), positive()))
{
  return filter(all(c), positive());
}

TEST(Filter, emptyRange_isEmpty) {
  ivec v;
  auto r = filterc(v);
  ASSERT_TRUE(r.empty());
}

TEST(Filter, oneWrong_isEmpty) {
  ivec v = { -1 };
  auto r = filterc(v);
  ASSERT_TRUE(r.empty());
}

TEST(Filter, oneRight_notEmpty) {
  ivec v = { 1 };
  auto r = filterc(v);
  ASSERT_FALSE(r.empty());
}

TEST(Filter, wrongRight_frontIsRight) {
  ivec v = { -1, 1 };
  auto r = filterc(v);
  ASSERT_EQ(1, r.front());
}

TEST(Filter, rightWrong_frontIsRight) {
  ivec v = { 1, -1 };
  auto r = filterc(v);
  ASSERT_EQ(1, r.front());
}

TEST(Filter, rightWrong_popFront_isEmpty) {
  ivec v = { 1, -1 };
  auto r = filterc(v);
  r.pop_front();
  ASSERT_TRUE(r.empty());
}

TEST(Filter, rightWrongRight_popFront_frontIsSecondRight) {
  ivec v = { 1, -1, 2 };
  auto r = filterc(v);
  r.pop_front();
  ASSERT_EQ(2, r.front());
}
